class CompanyProjectsController < ApplicationController
  before_filter :account_required, :login_required
  before_filter :admin_required, :except => :show
  
  def index
    @projects = Project.find_by_company(current_account.id)
  end
  
  def new
    @project = Project.new
  end
  
  # Create a new project
  def create
    @project = Project.new(params[:project])
    
    if @project.save
      User.find(params[:project][:project_manager]).projects << @project # Add project to manager
      flash[:notice] = "Project has been created."
      redirect_to projects_path
    else
      flash[:error] = "Project could not create."
      render :action => 'new'
    end
  end
  
  def show
    @project = Project.find(params[:id], :conditions => ['company_id = ?', current_account.id])
  end
end
